using System;
using System.Text;
using System.Windows;
using System.Windows.Controls;
namespace Coding4Fun.Phone.Controls
{
	public class PasswordInputPrompt : InputPrompt
	{
		private readonly StringBuilder stringBuilder_0 = new StringBuilder();
		public static readonly DependencyProperty PasswordCharProperty = DependencyProperty.Register("PasswordChar", typeof(char), typeof(PasswordInputPrompt), new PropertyMetadata('●'));
		public char PasswordChar
		{
			get
			{
				return (char)base.GetValue(PasswordInputPrompt.PasswordCharProperty);
			}
			set
			{
				base.SetValue(PasswordInputPrompt.PasswordCharProperty, value);
			}
		}
		public PasswordInputPrompt()
		{
			base.set_DefaultStyleKey(typeof(PasswordInputPrompt));
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			if (this.InputBox != null)
			{
				this.InputBox.add_TextChanged(new TextChangedEventHandler(this.method_10));
			}
		}
		private void method_10(object sender, TextChangedEventArgs e)
		{
			int num = this.InputBox.get_Text().get_Length() - this.stringBuilder_0.get_Length();
			if (num < 0)
			{
				num *= -1;
				int num2 = this.InputBox.get_SelectionStart() + 1 - num;
				if (num2 < 0)
				{
					num2 = 0;
				}
				this.stringBuilder_0.Remove(num2, num);
				base.Value = this.stringBuilder_0.ToString();
				return;
			}
			if (num > 0)
			{
				int selectionStart = this.InputBox.get_SelectionStart();
				string text = this.InputBox.get_Text().Substring(this.InputBox.get_SelectionStart() - 1, num);
				this.stringBuilder_0.Append(text);
				base.Value = this.stringBuilder_0.ToString();
				if (this.InputBox.get_Text().get_Length() >= 2)
				{
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.Insert(0, this.PasswordChar.ToString(), this.InputBox.get_Text().get_Length() - 1);
					stringBuilder.Append(text);
					this.InputBox.set_Text(stringBuilder.ToString());
				}
				this.InputBox.set_SelectionStart(selectionStart);
			}
		}
	}
}
